# python  jwt  时间日期
import jwt
from datetime import datetime, timedelta
from django.conf import settings


class JWTTool:
    # 参数 userid
    def get_token(self, userid):
        # 需要一个过期时间 为1天
        exp = datetime.utcnow() + timedelta(days=1)
        payload = {
            "userid": userid,
            "exp": exp
        }
        key = settings.SECRET_KEY
        return "Bearer " + jwt.encode(key=key, payload=payload, algorithm="HS256")


# 拿到类的实例
tool = JWTTool()
# print(tool.get_token(1))
